package com.rico.deploy.service.impl;

import com.github.pagehelper.PageHelper;
import com.rico.deploy.entity.Campus;
import com.rico.deploy.mapper.CampusMapper;
import com.rico.deploy.service.CampusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author 夏智力
 * @FileName CampusServiceImpl
 * @date 2021/5/2 17:04
 * @Software: IntelliJ IDEA
 */
@Service
public class CampusServiceImpl implements CampusService {

    @Autowired
    private CampusMapper campusMapper;

    @Override
    public List<Campus> selectAll() {
        return campusMapper.selectAll();
    }

    @Override
    public List<Campus> selectAll(Integer page,Integer limit) {
        PageHelper.startPage(page,limit);
        return campusMapper.selectAll();
    }

    @Override
    public Campus selectById(Integer id) {
        return campusMapper.selectByPrimaryKey(id);
    }

    @Override
    public String selectByCampusName(String campus_name) {
        Example example = new Example(Campus.class);
        example.createCriteria().andEqualTo("campusName",campus_name);
        return campusMapper.selectOneByExample(example).getCampusCode();
    }


    @Override
    public int insertCampus(Campus campus) {
        return campusMapper.insert(campus);
    }

    @Override
    public int deleteCampusById(Integer id) {
        return campusMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateCampus(Campus campus) {
        return campusMapper.updateByPrimaryKey(campus);
    }
}
